use mongodb::bson::serde_helpers::uuid_as_binary;
use mongodb::bson::{self, doc};
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;
use uuid::Uuid;
#[derive(Serialize, Deserialize, Debug)]
pub struct User {
    #[serde(with = "uuid_as_binary")]
    id: Uuid,
    pub telegram_id: i64,
    pub telegram_username: Option<String>,
    //#[serde(with = "uuid_as_binary")]
    pub joined: mongodb::bson::DateTime,
    pub show_real_url: bool,
}

impl User {
    pub fn id(&self) -> String {
        self.id.clone().to_string()
    }
}
#[derive(TypedBuilder, Serialize)]
pub struct UserBuilder {
    #[serde(with = "uuid_as_binary")]
    pub id: Uuid,
    pub telegram_id: i64,
    pub telegram_username: Option<String>,
    pub joined: bson::DateTime,
    //#[serde(with = "uuid_as_binary")]
    pub show_real_url: bool,
}
#[derive(Serialize, Deserialize, Debug, TypedBuilder)]
pub struct UserPost {
    #[serde(with = "uuid_as_binary")]
    id: Uuid,
    #[serde(with = "uuid_as_binary")]
    post_id: Uuid,
    #[serde(with = "uuid_as_binary")]
    user_id: Uuid,
    original_url: String,
    read: bool,
    read_at: Option<bson::DateTime>,
    favorite: bool,
    show_real_url: bool,
}
impl UserPost {
    pub fn original_url(&self) -> String {
        self.original_url.clone()
    }
    pub fn show_real_url(&self) -> bool {
        self.show_real_url
    }

    pub fn post_id(&self) -> Uuid {
        self.post_id
    }
    pub fn read(&self) -> bool {
        self.read
    }
    pub fn favourite(&self) -> bool {
        self.favorite
    }
}
#[derive(Serialize, Deserialize, Debug, TypedBuilder)]
pub struct Collection {
    #[serde(with = "uuid_as_binary")]
    id: Uuid,
    #[serde(with = "uuid_as_binary")]
    user_id: Uuid,
    name: String,
    elements: Vec<Element>,
    created: bson::DateTime,
}
impl Collection{
    pub fn len(&self)-> usize{
        self.elements.len()
    }
    pub fn name(&self) -> String{
        self.name.clone()
    }
    pub fn id(&self) -> Uuid {
        self.id
    }
}
#[derive(Serialize, Deserialize, Debug, TypedBuilder)]
pub struct Element{
    #[serde(with = "uuid_as_binary")]
    id: Uuid,
    #[serde(with = "uuid_as_binary")]
    original_id: Uuid,
        created: bson::DateTime,
}
